import React, {Component, PureComponent} from 'react';
import {AppRegistry, FlatList, StyleSheet, Text, View} from 'react-native';
import Devider from './Divider.js';
import DynamicItem from './DynamicItem.js';

export class MyListView extends Component {

    constructor(props) {
        super(props);
        this.state = {
            items: [],
            txt: ""
        }
    }

    componentDidMount() {
        fetch("http://m.zjgsmk.com/s/zjgsmk/v1/n15?is=5&page=1")
            .then((response) => response.json())
            .then((responseJson) => {
                console.log(responseJson);
                this.setState({
                    items: responseJson.r,
                    txt: responseJson.result
                });
            });
    }

    render() {
        return (
            <View>
                {/*<Text>*/}
                    {/*{this.state.txt}*/}
                {/*</Text>*/}
                <FlatList
                    data={this.state.items}
                    ItemSeparatorComponent={() => {
                        return (<Devider/>)
                    }}
                    renderItem={({item}) =>
                        <DynamicItem
                            imageSource={item.ico}
                            time={item.times}
                            imageContent={(item.fs.length == 0) ? null : (item.fs)[0].files}
                            title={item.title}
                            content={item.content}
                            address={item.addr}
                            channelName={item.label}
                        />}
                />
            </View>
            //<Text>{this.state.content}</Text>
            //https://ss3.baidu.com/-rVXeDTa2gU2pMbgoY3K/it/u=331642910,199523927&fm=202&mola=new&crop=v1
            //     < DynamicItem
            // imageSource = "https://ss3.baidu.com/-rVXeDTa2gU2pMbgoY3K/it/u=331642910,199523927&fm=202&mola=new&crop=v1"
            // time = "2017年10月31日"
            // imageContent = "http://imgsrc.baidu.com/image/c0%3Dshijue1%2C0%2C0%2C294%2C40/sign=407b2e95de3f8794c7f2406dba726481/a5c27d1ed21b0ef4c9eb5573d7c451da81cb3e98.jpg"
            // title = "2016年"
            // content = "2016年快要过去了，今年你都挣了些啥？"
            // address = "苏州市张家港"
            // channelName = "张家港市民卡"
            //     / >
        )
    }
}

const styles = StyleSheet.create({
    baseText: {
        fontSize: 20,
        marginTop: 10,
        padding: 5,
        color: '#aaa'
    },
    baseBgWhite: {
        backgroundColor: '#ffffff'
    }
})


AppRegistry.registerComponent('MyApplication', () => MyListView);
